package itbour.onetouchshow.activity.challengezone.material;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;
import java.util.List;

import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.SpUtils;
import itbour.onetouchshow.utils.T_;


public class MaterialPresenter extends BasePresenterImpl<MaterialContract.View> implements MaterialContract.Presenter {
    public void getDetailsList(MaterialActivity mainFragment, List<Integer> ids) {
        if (ids == null) {
            String appID = SpUtils.getInstance().getString("AppID");
            //Integer integer = new Gson().fromJson(appID, Integer.class).;
            ids = new Gson().fromJson(appID, new TypeToken<List<Integer>>() {
            }.getType());
        }
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("setIds", new Gson().toJson(ids));
        //pageNum	是
        stringStringHashMap.put("pageNum", mainFragment.mPageIndex);
        //页码 pageSize
        stringStringHashMap.put("pageSize", AppConst.PAGE_SIZE);
        //   页容量
        stringStringHashMap.put("withTotalPage", 1);

        HttpUtils.getInstance().executeGet(AppConfig.GETTMPLSETCONTENT_V1_0, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                L_.i("response  video===" + response);
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });
    }


    /**
     * 获取模板预览
     */
    public void loadThisPageInfo(int id) {
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", 610);
        stringStringHashMap.put("id", id);
        HttpUtils.getInstance().executeGet(AppConfig.GET_VERTICAL_MODEL_PREVIEW_V10, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showToastReal(exception);
            }

            @Override
            protected void onSuccess(String response) {
                mvpView.loadMateriaDetail(response);
            }
        });
    }

}
